#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

typedef struct point
{
    double x, y, z;
    bool operator<(const point &other)const{
		return z<other.z;
	}
} point;

 point points[50050];

int main()
{
    double count = 0.0;
   
    int N;
    scanf("%d", &N);
    for (int i=0; i<N; ++i){
        scanf("%lf %lf %lf", &points[i].x, &points[i].y, &points[i].z);
    }
    sort(points,points+N);
    for (int i = 1; i < N; ++i){
        count += sqrt(
            ((points[i].x - points[i-1].x) * (points[i].x - points[i-1].x)) 
            + ((points[i].y - points[i-1].y) * (points[i].y - points[i-1].y)) 
            + ((points[i].z  - points[i-1].z) * (points[i].z - points[i-1].z)) 
            );
    }

    printf("%0.3lf\n", count);
    return 0;
}